home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13711 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.6 KB

  1. Path: library.erc.clarkson.edu!rpi!not-for-mail
  2. From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
  3. Newsgroups: comp.lang.c++,comp.lang.c++.moderated,comp.sys.hp.hpux
  4. Subject: Re: [Q] gcc 2.7.2 + STL + HP_UX 9.05 = memory_leak ?
  5. Date: 26 Mar 1996 19:07:12 -0000
  6. Organization: unknown
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: Dietmar.Kuehl@uni-konstanz.de
  9. Message-ID: <4j9f90$5hv@netlab.cs.rpi.edu>
  10. References: <4j66lu$olu@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12. X-Original-Date: Tue, 26 Mar 96 18:07:33 +0100
  13.  
  14. In article <4j66lu$olu@netlab.cs.rpi.edu>
  15. cvjetko@PROBLEM_WITH_INEWS_GATEWAY_FILE.uni-erlangen.de (Miljenko
  16. Cvjetko) writes:
  17.  
  18. |> I was testing storing ptrs in STL container when I found
  19. |> out a memory-leak in STL implementation in following 
  20. |> example:
  21.  
  22. |> # include <list.h>           // STL list
  23. |> # include <stdlib.h>
  24.  
  25. |> class X
  26. |> {
  27. |>  protected:
  28. |>   list<int> nodes_;  // this line causes 
  29. |>                      // memory leak problems!!!
  30. |>                      //     under HP_UX 9.05
  31. |>                      // not under Borland C/C++ + DOS
  32. |> };
  33.  
  34. |> void f()
  35. |> {
  36. |>  X x1;
  37. |> }
  38.  
  39. |> int main()
  40. |> {
  41. |>  memorymap(1);
  42. |>  f();
  43. |>  memorymap(1);   // list is out of scope 
  44. |>  return 0;
  45. |> }
  46. |> - ------------------------------------------
  47. |> Result:
  48.  
  49. |> arenastart               :          0
  50. |> arenaend                 :          0
  51. |> # of blocks              :          0
  52. |> # of free blocks         :          0
  53. |> # of used blocks         :          0
  54. |> # of smblk blks          :          0
  55. |> total space used         :          0
  56. |> space in free blocks     :          0
  57. |> space in used blocks     :          0
  58. |> space in smblk blocks    :          0
  59. |> 1073748164: node block 8192
  60. |> 1073756356: free 1848
  61.  
  62. |> arenastart               : 1073748164
  63. |> arenaend                 : 1073758204
  64. |> # of blocks              :          2
  65. |> # of free blocks         :          1
  66. |> # of used blocks         :          1
  67. |> # of smblk blks          :          0
  68. |> total space used         :      10040
  69. |> space in free blocks     :       1848
  70. |> space in used blocks     :       8192
  71. |> space in smblk blocks    :          0
  72. |> - -------------------------------------------
  73. |> In addition, this code was compiled under
  74. |> BC 4.5 and had no memory leak! Am I
  75. |> misinterpreting memorymap() function call?
  76. |> Same was with some other containers (set,vector).
  77. |> Any suggestions?
  78.  
  79. I doubt that this is significant.  I suspect that the missing block is
  80. some sort of pseudo-static allocated by the implementation.  I know,
  81. for example, that older versions of the Sun compiler would allocate an
  82. additional block the first time you new'ed a C style array.  And most
  83. implementations will allocate the iobuffer on the first output.
  84. Neither of these blocks will ever be freed.
  85.  
  86. What you want to check is to call the function in a loop.  If the
  87. number of unfreed blocks increases with the number of passes in the
  88. loop, then you've got a real problem.  I suspect, however, that you
  89. will find that you always have one unfreed block, whether you execute
  90. the loop once, or a 1000 times.
  91.  
  92. --
  93. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  94. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  95. Conseils, itudes et rialisations en logiciel orienti objet --
  96.                 -- A la recherche d'une activiti dans une region francophone
  97.  
  98.  
  99.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  100.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  101.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  102.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  103.